#include<iostream>
using namespace std;
#include<vector>
class MyCalendar {
public:
    MyCalendar() {

    }

    bool book(int startTime, int endTime) {
        if (vec.size() == 0 || vec[0].first >= endTime) {
            vec.insert(vec.begin(), { startTime,endTime });
            return true;
        }
        int l = 0, r = vec.size()-1;
        while (l < r) {
            int mid = l + (r - l+1) / 2;
            if (vec[mid].second <= startTime)
                l = mid;
            else
                r = mid - 1;
        }
        if (vec[l].second > startTime||(l+1<vec.size()&&vec[l+1].first<endTime))
            return false;
        vec.insert(vec.begin()+l + 1, { startTime,endTime });
        return true;
    }
    vector<pair<int, int>> vec;
};

/**
 * Your MyCalendar object will be instantiated and called as such:
 * MyCalendar* obj = new MyCalendar();
 * bool param_1 = obj->book(startTime,endTime);
 */
int main() {
    MyCalendar test;
    test.book(10, 20);
    test.book(15, 25);
    test.book(20, 30);
}